package com.gitee.fastmybatis.spring.boot.autoconfigure;

import com.gitee.fastmybatis.core.FastmybatisContext;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;

/**
 * @author 六如
 */
@Configuration
public class MybatisApplicationContextConfig implements BeanPostProcessor {

    @Autowired
    private ApplicationContext applicationContext;

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        FastmybatisContext.setApplicationContext(applicationContext);
        return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
    }

}
